package top.yehot.kettle.boot.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.pentaho.di.core.database.DatabaseMeta;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import top.yehot.cmm.util.core.model.vo.LabelValueVO;
import top.yehot.cmm.util.spring.anns.ResponseResult;
import top.yehot.kettle.boot.core.SysConst;
import top.yehot.kettle.boot.enums.GlobalParamEnum;
import top.yehot.kettle.boot.enums.RepTypeEnum;
import top.yehot.kettle.boot.service.DatabaseTypeService;

/**
 * 统一枚举
 * 
 * @author lquan
 * @date 2022年5月16日 下午1:55:17
 */
@Api(tags = "统一枚举")
@RestController
@RequestMapping(SysConst.VERSION + "/enums")
@AllArgsConstructor
@ResponseResult
public class EnumsController {
	
	private final DatabaseTypeService databaseTypeService;
	
    @ApiOperation(value = "数据库类型列表")
    @GetMapping("databaseType")
    public List<LabelValueVO> databaseType() {
    	return databaseTypeService.getAll();
    }
    
    @ApiOperation(value = "资源库类型")
    @GetMapping("repositoryType")
    public List<LabelValueVO> repositoryType() {
    	return Arrays.stream(RepTypeEnum.values()).map(e -> LabelValueVO.of(e.name(), e.getDetail())).collect(Collectors.toList());
    }

    @ApiOperation(value = "数据库访问类型枚举")
    @GetMapping("databaseAccessType")
    public List<LabelValueVO> databaseAccessType() {
        // 数据库访问类型编码
        String[] dbAccessTypeCode = DatabaseMeta.dbAccessTypeCode;
        // 数据库访问类型编码说明
        String[] dbAccessTypeDesc = DatabaseMeta.dbAccessTypeDesc;
        
        List<LabelValueVO> list = new ArrayList<LabelValueVO>();
        for (int i = 0; i < dbAccessTypeCode.length; i++) {
        	list.add(LabelValueVO.of(dbAccessTypeCode[i], dbAccessTypeDesc[i]));
        }
        return list;
    }
    
    @ApiOperation(value = "参数类型")
    @GetMapping("paramType")
    public List<LabelValueVO> paramType() {
    	return Arrays.stream(GlobalParamEnum.values()).map(e -> LabelValueVO.of(e.name(), e.getDetail())).collect(Collectors.toList());
    }
    
}
